﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;

namespace dzs.Web.supply
{
    public partial class ListPutOperationEvaluation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["login"] != null)
                {
                    DataSet ds = Session["login"] as DataSet;

                    int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                    int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                    Bind(user_id);
                }
                //Bind(11);

            }

        }

        private void Bind(int user_id)
        {
            //到货评价不为null,安装调试确认状态不为null时
            StringBuilder str = new StringBuilder(" user_id=" + user_id + " and installationStatus is not null and arrivalEvaluationStatus is not null ");

            //投运不为null
            str.Append(" and putOperationStatus is not null ");
            //投运评价状态为null
            str.Append(" and putOperationEvaluationStaus is null ");


            if (!string.IsNullOrEmpty(txt_material.Text))
            {
                str.Append(" and material like '%" + txt_material.Text + "%' ");
            }
            if (!string.IsNullOrEmpty(txt_projectName.Text))
            {
                str.Append(" and projectName like '%" + txt_projectName.Text + "%' ");
            }

            DataSet ds = new Maticsoft.BLL.supplyPlan().GetListSumInnumsInfo(str.ToString());
            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();

        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "lbn_tyztqr")
            {
                if (e.CommandArgument != null)
                {
                    string supplyPlanId = e.CommandArgument.ToString();

                    Maticsoft.BLL.supplyPlan sm = new Maticsoft.BLL.supplyPlan();

                    Maticsoft.Model.supplyPlan s = sm.GetModel(int.Parse(supplyPlanId));

                    s.putOperationEvaluationStaus = "已确认";
                    s.putOperationEvaluationStausDate = DateTime.Now;

                    if (sm.Update(s))
                    {
                        if (Session["login"] != null)
                        {
                            DataSet ds = Session["login"] as DataSet;

                            int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                            Bind(user_id);
                        }
                        Maticsoft.Common.MessageBox.Show(this, "投运评价状态已确认，确认日期：" + s.arrivalEvaluationStatusDate);
                    }
                }
                //发送质量计划
                if (e.CommandName == "lbn_fszljh")
                {
                    string supplyPlanId = e.CommandArgument.ToString();

                }
            }
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lbl_nums = e.Row.FindControl("lbl_nums") as Label;//计划数量
                Label lbl_innums = e.Row.FindControl("lbl_innums") as Label;//累计入库量
                Label lbl_beComplatedTime = e.Row.FindControl("lbl_beComplatedTime") as Label;//竣工日期
                LinkButton lbn_tyztqr = e.Row.FindControl("lbn_tyztqr") as LinkButton;

                decimal nums = 0;
                decimal innums = 0;

                if (!string.IsNullOrEmpty(lbl_nums.Text))
                {
                    nums = decimal.Parse(lbl_nums.Text);
                }
                if (!string.IsNullOrEmpty(lbl_innums.Text))
                {
                    innums = decimal.Parse(lbl_innums.Text);
                }

                if (nums == innums)
                {
                    lbn_tyztqr.Enabled = true;
                }
                else
                {
                    lbn_tyztqr.Enabled = false;

                }


            }
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;

                int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                Bind(user_id);
            }
        }

        protected void btn_reload_Click(object sender, EventArgs e)
        {

        }

        protected void btn_sel_Click(object sender, EventArgs e)
        {
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;

                int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                Bind(user_id);
            }
        }
    }
}